package oa.hleast.xswl.common.enums;

import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Getter
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("优惠券类型")
public enum CouponTypeEnum {
    /**
     * 平台券
     */
    PLATFORM(1, "平台券"),
    /**
     * 积分兑换券
     */
    EXCHANGE(2, "积分兑换券");

    private Integer code;
    private String detail;

    public static Map<Integer, String> enum2Map() {
        Map<Integer, String> map = Arrays.stream(CouponTypeEnum.values())
                .collect(Collectors.toMap(s -> s.code, CouponTypeEnum::getDetail));
        return map;
    }

    public static List<Map<Object, Object>> enum2List() {

        return Arrays.stream(CouponTypeEnum.values()).map(value -> {
            Map<Object, Object> map = new LinkedHashMap<>();
            map.put("code", value.getCode());
            map.put("detail", value.getDetail());
            return map;
        }).collect(Collectors.toList());

    }

    public static CouponTypeEnum getValue(Integer code) {
        for (CouponTypeEnum value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }

}
